From bb57d8f7267e33bb68541201e40e49ac133a6dba Mon Sep 17 00:00:00 2001 From: robertl Date: Mon, 1 Nov 2004 05:14:22 +0000 Subject: [PATCH] Add hiketech format. --- gpsbabel/hiketech.c | 241 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 241 insertions(+) create mode 100644 gpsbabel/hiketech.c diff --git a/gpsbabel/hiketech.c b/gpsbabel/hiketech.c new file mode 100644 index 000000000..97f11066d --- /dev/null +++ b/gpsbabel/hiketech.c @@ -0,0 +1,241 @@ +/* + Access Hiketech XML data files. + + Copyright (C) 2004 Robert Lipe, robertlipe@usa.net + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA + + */ + +#include "defs.h" +#include "xmlgeneric.h" + +static FILE *ofd; +static waypoint *wpt_tmp; +static route_head *trk_head; + + +#define MYNAME "hiketech" + +static +arglist_t hiketech_args[] = { + {0, 0, 0, 0, 0} +}; + +/* Waypoints */ +static xg_callback ht_wpt_s; +static xg_callback ht_wpt_e; +static xg_callback ht_ident; +static xg_callback ht_sym; +static xg_callback ht_lat; +static xg_callback ht_long; +static xg_callback ht_alt; + +/* Tracks */ +static xg_callback ht_trk_s, ht_trk_e; +static xg_callback ht_trk_ident; +static xg_callback ht_trk_pnt_s, ht_trk_pnt_e; +static xg_callback ht_trk_utc; +static xg_callback ht_trk_lat; +static xg_callback ht_trk_long; +static xg_callback ht_trk_alt; + +static xg_tag_mapping ht_map[] = { + { ht_wpt_s, cb_start, "/hiketech/gpsdata/wpt" }, + { ht_wpt_e, cb_end, "/hiketech/gpsdata/wpt" }, + { ht_ident, cb_cdata, "/hiketech/gpsdata/wpt/ident" }, + { ht_sym, cb_cdata, "/hiketech/gpsdata/wpt/sym" }, + { ht_lat, cb_cdata, "/hiketech/gpsdata/wpt/lat" }, + { ht_long, cb_cdata, "/hiketech/gpsdata/wpt/long" }, + { ht_alt, cb_cdata, "/hiketech/gpsdata/wpt/alt" }, + + { ht_trk_s, cb_start, "/hiketech/gpsdata/trk" }, + { ht_trk_e, cb_end, "/hiketech/gpsdata/trk" }, + { ht_trk_ident, cb_cdata, "/hiketech/gpsdata/trk/ident" }, + { ht_trk_pnt_s, cb_start, "/hiketech/gpsdata/trk/pnt" }, + { ht_trk_pnt_e, cb_end, "/hiketech/gpsdata/trk/pnt" }, + { ht_trk_utc, cb_cdata, "/hiketech/gpsdata/trk/pnt/utc" }, + { ht_trk_lat, cb_cdata, "/hiketech/gpsdata/trk/pnt/lat" }, + { ht_trk_long, cb_cdata, "/hiketech/gpsdata/trk/pnt/long" }, + { ht_trk_alt, cb_cdata, "/hiketech/gpsdata/trk/pnt/alt" }, + { NULL, 0, NULL} +}; + +void +hiketech_rd_init(const char *fname) +{ + xml_init(fname, ht_map); +} + +void +hiketech_read(void) +{ + xml_read(); +} + +void +hiketech_rd_deinit(void) +{ +} + +void +hiketech_wr_init(const char *fname) +{ + ofd = xfopen(fname, "w", MYNAME); +} + +void +hiketech_wr_deinit(void) +{ + fclose(ofd); +} + +static void +hiktech_waypt_pr(const waypoint *wpt) +{ + fprintf(ofd, "\n"); + write_xml_entity(ofd, "\t", "ident", wpt->shortname); + write_optional_xml_entity(ofd, "\t", "sym", wpt->icon_descr); + fprintf(ofd, "\t%f\n", wpt->latitude); + fprintf(ofd, "\t%f\n", wpt->longitude); + + /* + * These probably aren't technicallyconstants, but it's all + * we can do for now. + */ + fprintf(ofd, "\t\n\t\tFAFFB4\n\t\tFF8000\n\t\n"); + fprintf(ofd, "\n"); +} + +void +hiketech_write(void) +{ + fprintf(ofd, "\n"); + fprintf(ofd, "\n"); + waypt_disp_all(hiktech_waypt_pr); + fprintf(ofd, "\n"); + fprintf(ofd, "\n"); +} + +void ht_wpt_s(const char *args, const char **unused) +{ + wpt_tmp = waypt_new(); +} + +void ht_ident(const char *args, const char **unused) +{ + wpt_tmp->shortname = xstrdup(args); +} + +void ht_sym(const char *args, const char **unused) +{ + wpt_tmp->icon_descr = xstrdup(args); + wpt_tmp->icon_descr_is_dynamic = 1; +} + +void ht_lat(const char *args, const char **unused) +{ + wpt_tmp->latitude = atof(args); +} + +void ht_long(const char *args, const char **unused) +{ + wpt_tmp->longitude = atof(args); +} + +void ht_alt(const char *args, const char **unused) +{ + wpt_tmp->altitude = atof(args); +} + +void ht_wpt_e(const char *args, const char **unused) +{ + waypt_add(wpt_tmp); + wpt_tmp = NULL; +} + +void ht_trk_s(const char *args, const char **unused) +{ + trk_head = route_head_alloc(); + track_add_head(trk_head); +} + +void ht_trk_e(const char *args, const char **unused) +{ + +} + +void ht_trk_ident(const char *args, const char **unused) +{ + trk_head->rte_name = xstrdup(args); +} + +void ht_trk_pnt_s(const char *args, const char **unused) +{ + wpt_tmp = waypt_new(); +} + +void ht_trk_pnt_e(const char *args, const char **unused) +{ + route_add_wpt(trk_head, wpt_tmp); +} + +void ht_trk_utc(const char *args, const char **unused) +{ + struct tm tm; + time_t utc; + + sscanf(args, "%d-%d-%d %d:%d:%d", + &tm.tm_year, &tm.tm_mon, + &tm.tm_mday, &tm.tm_hour, + &tm.tm_min, &tm.tm_sec); + tm.tm_mon -= 1; + tm.tm_year -= 1900; + tm.tm_isdst = 0; + + utc = mktime(&tm) + get_tz_offset() ; + + wpt_tmp->creation_time = utc; +} + +void ht_trk_lat(const char *args, const char **unused) +{ + wpt_tmp->latitude = atof(args); +} + +void ht_trk_long(const char *args, const char **unused) +{ + wpt_tmp->longitude = atof(args); +} + +void ht_trk_alt(const char *args, const char **unused) +{ + wpt_tmp->altitude = atof(args); +} + + + +ff_vecs_t hiketech_vecs = { + ff_type_file, + hiketech_rd_init, + hiketech_wr_init, + hiketech_rd_deinit, + hiketech_wr_deinit, + hiketech_read, + hiketech_write, + NULL, + hiketech_args +}; + -- 2.30.2